<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>openlayers扩展实例</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/openlayers/dist/ol.css">
  <style>
    html, body, #map {
      height: 100%;
      padding: 0;
      margin: 0;
    }
  </style>
</head>
<body>
<div id="map"></div>
<script src="https://cdn.jsdelivr.net/npm/openlayers/dist/ol.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.js"></script>
<script type="text/javascript" src="https://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ol3-echarts/dist/ol3Echarts.js"></script>
<!--<script src="../../../dist/ol3Echarts.js"></script>-->
<script>
  var Maps = new ol.Map({
    target: 'map',
    layers: [
      new ol.layer.Tile({
        preload: 4,
        source: new ol.source.OSM()
      })
    ],
    loadTilesWhileAnimating: true,
    view: new ol.View({
      projection: 'EPSG:4326',
      center: [113.53450137499999, 34.44104525],
      zoom: 5
    })
  });
  var styleFunction = function (feature) {
    var num = feature.getProperties()['childNum'];
    return new ol.style.Style({
      stroke: new ol.style.Stroke({
        color: '#162436',
        width: 1
      }),
      fill: new ol.style.Fill({
        color: num > 3 ? '#ff4500' : (num > 2 ? '#c1e682' : '#8cd0ef')
      })
    })
  };
  var vectorSource = new ol.source.Vector({
    features: (new ol.format.GeoJSON()).readFeatures(ol3Echarts.formatGeoJSON(echarts.getMap('world')['geoJson']))
  });
  var vectorLayer = new ol.layer.Vector({
    source: vectorSource,
    style: styleFunction
  });
  Maps.addLayer(vectorLayer);
</script>
</body>
</html>
